require('../../fonts/iconfont.css')
/**
 * 工具函数
 */
const utils = {
    createToast: function (status, msg) {
        let toast = document.createElement('div')
        toast.className = 'toast'
        let html = `
    <p>
    <span class='icon'>${status === 0 ? '√' : 'x'}</span>
    </p>
    <p>${msg}</p>
    `
        toast.innerHTML = html
        let bodyDom = document.querySelector('body')
        bodyDom.appendChild(toast)
        setTimeout(function () {
            toast.remove()
        }, 1000)
    },
    createFooter: function (page) {
        let footer = document.createElement('footer');
        footer.className = 'dpflex jscon'
        // 如果被选中的页面  footer-item active  
        //没有被选中的页面   footer-item
        let html = `
            <a href="./home.html">
            <div class="${page === 'home' ? 'footer-item active' : 'footer-item'}">
              <p>
                <i class="iconfont icon-shouye"></i>
              </p>
              <p>首页</p>
            </div>
          </a>
          <a href="./sports.html">
            <div class="${page === 'sports' ? 'footer-item active' : 'footer-item'} ">
              <p>
                <i class="iconfont icon-xindiantu"></i>
              </p>
              <p>运动</p>
            </div>
          </a>
          <a href="./about.html">
            <div class="${page === 'about' ? 'footer-item active' : 'footer-item'}">
              <p>
                <i class="iconfont icon-wode"></i>
              </p>
              <p>我的</p>
            </div>
          </a>
        `;
        footer.innerHTML = html;
        document.querySelector('body').appendChild(footer);
    },
    /**
   * @ strToObj
   * @ str String  '?id=6&name=zangmazi'
   * @return Object  {id:6,name:zhangmazi}
   */
  strToObj: function (str) {
    let obj = {};
    str = str.substr(1);
    //id=6&name=zangmazi
    let arr = str.split('&');
    //['id=6','name=zhangmazi']

    arr.forEach(function (item, index) {
      let arr1 = item.split('=');
      //[id,6]  [name,zhangmazi]
      obj[arr1[0]] = arr1[1];
    })
    return obj;
  }
}
/*
@createToast 封装组件
*/

window.utils = utils